/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.bean;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.ruipengkj.commons.util.UUID;

/**
 * 说明： Entity Name 单据商品明细
 * 
 * @Author：李智深
 * @Date：2012-03-14
 */
@Entity
@Table(name="ruipeng_tb_TBillDetail")
public class TBillDetail implements Serializable{

	private static final long serialVersionUID = 1L;

	private String DetailID;// 明细编号DECIMAL(20,3)PK
	
	private byte BillType;// 单据类型TINYINT所有的单据的商品明细都在这张表中，集中在一起也方便统计，这里的单据类型
							// 1为采购单 2为采购退货单 3为销售定单 4为销售退货单 5为员工领用单 6为报损单
							// 7为仓库调拨单 8其他原因出库单 9会员充值     //
	private String BillID;// 单据编号CHAR(15)   //
	
	private String CommodityID;// 商品编号
	
	private int Num;// 商品数量INTEGER
	
	private double Price;// 价格DECIMAL(20,3)
	
	private double Discount;// 折扣;
	
	private String DiscountID;// 折扣编号CHAR(15)
	
//	private Double avgPrice;//加权价，就是成本价，从出库仓库中获取
	
	private TCommodity commodity;//商品，用于添加使用，不进数据库
	
	private Date HappenTime;//操作时间，用于报表查询，不进数据库
	
	private double NumPrice;//总计  ，用于表格查询，不进数据库
	
	private boolean isFlag;//是否选中  ，用于表格查询，不进数据库
	
	private byte Source;//订单来源，用于表格显示，不进数据库
	
	private Set<TBillDetailDes> TBillDetailDes=new HashSet<TBillDetailDes>(0);//单据商品说明
	
	public TBillDetail(){};
	
	/**id*/
	public TBillDetail(String detailID) {
		super();
		DetailID = detailID;
	}

	public TBillDetail(int num, double price) {
		super();
		Num = num;
		Price = price;
	}
	/**商品ID， 数量， 价格*/
	public TBillDetail(String commodityID, int num, double price) {
		super();
		CommodityID = commodityID;
		Num = num;
		Price = price;
	}
	/**单据类型   单据编号*/
	public TBillDetail(byte billType, String billID) {
		super();
		BillType = billType;
		BillID = billID;
	}
	@Id
	@Column(name = "DetailID",length=15)
	public String getDetailID() {
		return DetailID;
	}

	public void setDetailID(String detailID) {
		DetailID = detailID;
	}

	@Column(name = "BillType")
	public byte getBillType() {
		return BillType;
	}

	public void setBillType(byte billType) {
		BillType = billType;
	}

	@Column(name = "BillID", length = 15)
	public String getBillID() {
		return BillID;
	}

	public void setBillID(String billID) {
		BillID = billID;
	}

	@Column(name = "CommodityID", length = 15)
	public String getCommodityID() {
		return CommodityID;
	}

	public void setCommodityID(String commodityID) {
		CommodityID = commodityID;
	}

	@Column(name = "Num")
	public int getNum() {
		return Num;
	}

	public void setNum(int num) {
		Num = num;
	}

	@Column(name = "Price", precision = 20, scale = 3)
	public double getPrice() {
		return Price;
	}

	public void setPrice(double price) {
		Price = price;
	}

	@Column(name = "Discount", precision = 20, scale = 3)
	public double getDiscount() {
		return Discount;
	}

	public void setDiscount(double discount) {
		Discount = discount;
	}
	
	@Column(name = "DiscountID", length = 15)
	public String getDiscountID() {
		return DiscountID;
	}

	public void setDiscountID(String discountID) {
		DiscountID = discountID;
	}
//	@Column(name = "avgPrice", precision = 20, scale = 3)
//	public Double getAvgPrice() {
//		return avgPrice;
//	}
//
//	public void setAvgPrice(Double avgPrice) {
//		if(avgPrice==null){
//			this.avgPrice = 0.00;
//		}else{
//			this.avgPrice = avgPrice;
//		}
//	}

	@Transient
	public TCommodity getCommodity() {
		return commodity;
	}

	public void setCommodity(TCommodity commodity) {
		this.commodity = commodity;
	}
	
	@Transient
	public Date getHappenTime() {
		return HappenTime;
	}

	public void setHappenTime(Date HappenTime) {
		this.HappenTime = HappenTime;
	}
	
	@OneToMany(mappedBy="TBillDetail",fetch=FetchType.EAGER)
	@JoinColumn(name="DetailID")
	public Set<TBillDetailDes> getTBillDetailDes() {
		return TBillDetailDes;
	}

	public void setTBillDetailDes(Set<TBillDetailDes> tBillDetailDes) {
		TBillDetailDes = tBillDetailDes;
	}
	
	@Transient
	public double getNumPrice() {
		return NumPrice;
	}

	public void setNumPrice(double NumPrice) {
		this.NumPrice = NumPrice;
	}
	@Transient
	public boolean isFlag() {
		return isFlag;
	}

	public void setFlag(boolean isFlag) {
		this.isFlag = isFlag;
	}

	@Transient
	public byte getSource() {
		return Source;
	}

	public void setSource(byte source) {
		Source = source;
	}

}
